package com.interview.salesorder.entity;

import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;
import org.springframework.format.annotation.DateTimeFormat;

import com.interview.customer.entity.Customer;
import com.interview.employeeInfo.entity.EmployeeInfo;
import com.interview.orderdetail.entity.OrderDetail;

@Entity
@Table(name = "sales_order")
public class SalesOrder {
	@Id
	@GenericGenerator(name = "idGenerator", strategy = "uuid")
	@GeneratedValue(generator = "idGenerator")
	private String id;

	// 订单编号
	@Column(name = "order_code")
	private String orderCode;
	
	// 客户
	@Column(name = "customer_id")
	private String customerId;

	// 员工
	@Column(name = "employeeInfo_id")
	private String employeeInfoId;

	// 总花费
	@Column(name = "sum_cost")
	private double sumCost;

	// 员工名
	@Column(name = "employeeInfo_name")
	private String employeeInfoName;

	// 客户名
	@Column(name = "customer_name")
	private String customerName;

	@DateTimeFormat(pattern = "MM/dd/yyyy")
	@Column(name = "order_create_time")
	private Date orderCreateTime;

	@OneToMany(orphanRemoval = true, cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinColumn(name = "order_id")
	private List<OrderDetail> orderList;
	
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public List<OrderDetail> getOrderList() {
		return orderList;
	}

	public void setOrderList(List<OrderDetail> orderList) {
		this.orderList = orderList;
	}

	public String getOrderCode() {
		return orderCode;
	}

	public void setOrderCode(String orderCode) {
		this.orderCode = orderCode;
	}

	public String getCustomerId() {
		return customerId;
	}

	public void setCustomerId(String customerId) {
		this.customerId = customerId;
	}

	public String getEmployeeInfoId() {
		return employeeInfoId;
	}

	public void setEmployeeInfoId(String employeeInfoId) {
		this.employeeInfoId = employeeInfoId;
	}

	public double getSumCost() {
		return sumCost;
	}

	public void setSumCost(double sumCost) {
		this.sumCost = sumCost;
	}

	public String getEmployeeInfoName() {
		return employeeInfoName;
	}

	public void setEmployeeInfoName(String employeeInfoName) {
		this.employeeInfoName = employeeInfoName;
	}

	public String getCustomerName() {
		return customerName;
	}

	public void setCustomerName(String customerName) {
		this.customerName = customerName;
	}

	public Date getOrderCreateTime() {
		return orderCreateTime;
	}

	public void setOrderCreateTime(Date orderCreateTime) {
		this.orderCreateTime = orderCreateTime;
	}
//----------------------------------------------------------------------------
	/*
	 * 
	 * cannot simultaneously fetch multiple bags 异常
	 * 
	@ManyToOne(optional =false,fetch=FetchType.LAZY)
	@JoinColumn(name = "customer_id", referencedColumnName = "id")
	private Customer customer;
	
	@ManyToOne(optional =false,fetch=FetchType.LAZY)
	@JoinColumn(name = "employeeInfo_id", referencedColumnName = "id")
	private EmployeeInfo employeeInfo;
	
	public Customer getCustomer() {
		return customer;
	}

	public void setCustomer(Customer customer) {
		this.customer = customer;
	}

	public EmployeeInfo getEmployeeInfo() {
		return employeeInfo;
	}

	public void setEmployeeInfo(EmployeeInfo employeeInfo) {
		this.employeeInfo = employeeInfo;
	}
*/
}
